//
//  ZCXVideoCollectionViewCell.m
//  LoveOfPet
//
//  Created by dllo on 15/11/14.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "ZCXVideoCollectionViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>

#define HEIGHT  [[UIScreen mainScreen]bounds].size.height / 667
#define WIDTH   [[UIScreen mainScreen]bounds].size.width / 375
@interface ZCXVideoCollectionViewCell ()
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIImageView *imageV;
@property (nonatomic, retain) UIImageView *userImageV;
@property (nonatomic, retain) UIImageView *backImageV;

@end

@implementation ZCXVideoCollectionViewCell
- (void)dealloc{
    [_imageV release];
    [_titleLabel release];
    [_videoModel release];
    [_userImageV release];
    [_backImageV release];
    [super dealloc];
}
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageV = [[UIImageView alloc]init];
        [self.contentView addSubview:_imageV];
        
        
        self.backImageV = [[UIImageView alloc]init];
        [_imageV addSubview:_backImageV];
        
        self.titleLabel = [[UILabel alloc]init];
        [_imageV addSubview:_titleLabel];
        
        self.userImageV = [[UIImageView alloc]init];
        [_imageV addSubview:_userImageV];
        
        [_userImageV release];
        [_titleLabel release];
        [_backImageV release];
        [_imageV release];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    _imageV.frame = CGRectMake(0,0, self.frame.size.width, self.frame.size.height);
    _userImageV.frame = CGRectMake(5 * WIDTH, self.imageV.frame.size.height - 35 * HEIGHT, 30 * WIDTH, 30 * HEIGHT);
    _titleLabel.frame = CGRectMake(40 * WIDTH, self.imageV.frame.size.height - 35 * HEIGHT, self.imageV.frame.size.width - 40 * WIDTH, 25 * HEIGHT);
    _backImageV.frame = CGRectMake(0, self.imageV.frame.size.height - 70 * HEIGHT, self.frame.size.width, 70 * HEIGHT);
    _backImageV.image = [UIImage imageNamed:@"2"];
}
- (void)setVideoModel:(ZCXVideoModel *)videoModel{
    if (_videoModel != videoModel) {
        [_videoModel release];
        _videoModel = [videoModel retain];
    }
    [_imageV sd_setImageWithURL:[NSURL URLWithString:videoModel.recommend_cover_pic]];
    _titleLabel.shadowColor = [UIColor grayColor];
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.numberOfLines = 0;
    _titleLabel.font = [UIFont systemFontOfSize:14 * WIDTH];
    _titleLabel.text = videoModel.recommend_caption;
    
    _userImageV.backgroundColor = [UIColor grayColor];
    _userImageV.layer.masksToBounds = YES;
    _userImageV.layer.cornerRadius = 15 * WIDTH;
    [_userImageV sd_setImageWithURL:[NSURL URLWithString:[[videoModel.media objectForKey:@"user"] objectForKey:@"avatar"]]];
}
@end
